﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Zatify.Domain.Abstract;
using System.Net.Mail;
using System.Configuration;

namespace Zatify.Domain.Concrete
{
    public class ZatifyPasswordRecoverySender : IPasswordRecoveryService
    {
        public void SendPasswordRecoveryToEmail(string message, string email)
        {
            MailMessage mail = new MailMessage();
            SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");

            SmtpServer.EnableSsl = true;
            SmtpServer.Credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings.Get("EmailUser"), ConfigurationManager.AppSettings.Get("EmailPassword"));
            SmtpServer.Port = 587; // Gmail works on this port 

            mail.From = new MailAddress(ConfigurationManager.AppSettings.Get("EmailAddress"));
            mail.To.Add(email);
            mail.Subject = "Password recovery";
            mail.Body = String.Format("Password: {0}", message);

            SmtpServer.Send(mail);
        }

        public void SendPasswordRecoveryToMobile(string message, string phone)
        {
            SmsSendService.SendSms(String.Format("Password: {0}", message), phone);
        }
    }
}
